package itsur.arquitecturas.implicitinvocation;

/**************************************************************************************
** Class name: Menus
** Author: A.J. Lattanze
** Date: //
** Version 1.0
***************************************************************************************
** Purpose: Assignment 3 for SE 17-655, Architectures for Software Systems.
** This class is presents the user with menus, accepts their choice, ensures their
** choice is valid, and returns their choice to the caller.
** (reused from assignment 2)
**
** Abstract: There are several menus that can be presented as follows:
**
**	MainMenu() - The MainMenu() method presents the following menu choices:
**
**		1) List Students
**		2) List Courses
**		3) List Courses a Student has Registered for
**		4) List Students Registered for a Course
**		5) Register a Student for a Course
**		X) Exit
**
**	public Student PickStudent( StudentList ListObject ) - This method asks the
**	user to enter a student ID.  The student ID is then checked to see if its
**	valid (i.e. in the student list).
**
**	public Course PickCourse( CourseList ListObject ) - This method asks the user
**	to enter a course ID and a section number.  The course is then checked to see if
**	its valid (i.e. in the course list).
**
** Modification Log
**************************************************************************************
***************************************************************************************
** Modification by: ITSUR
** Date: 02/12/08
** Version 1.6
** Description: This class has been changed to add the choice:
*			7)list courses that the student has already taken.
**************************************************************************************/

public class Menus
{
	// This is the main menu method

	public char MainMenu()
	{
		Termio Terminal = new Termio();
		char UserChoice = ' ';
		boolean Error = true;

	   	while( Error )
		{
		   System.out.println( "\n\n\n1) List Students" );
		   System.out.println( "2) List Courses" );
		   System.out.println( "3) List Courses a Student has Registered for" );
		   System.out.println( "4) List Students Registered for a Course" );
		   System.out.println( "5) Register a Student for a Course" );
		   
		   //ITSUR component
		   System.out.println( "6) List Pending CORE courses for a Student" );
		   System.out.println( "7) List courses that student has already taken." );
		   System.out.println( "8) Register a Student for a Course (automatic section selection)" );
		   
		   System.out.println( "X) Exit" );
		   System.out.print( "\nEnter your choice and press return >> " );

		   UserChoice = Terminal.KeyboardReadChar();

		   if ((UserChoice != 'X') && (UserChoice != 'x') && (UserChoice < '1') &&
			 (UserChoice != '2') && (UserChoice != '3') && (UserChoice < '4') &&
			 (UserChoice != '5')&&(UserChoice != '6') &&(UserChoice != '7') &&(UserChoice != '8'))
		   {
			System.out.print( "\n\n*** Invalid Choice:: " + UserChoice + " ***" );

		   } else {

			Error = false;

		   } // if
		} // while

		return( UserChoice );

	} // MainMenu

	// This method allows the user to select a student

	public Student PickStudent( StudentList ListObject )
	{
		Termio Terminal = new Termio();
		String UserChoice;
		Student StudentObject = null;

		System.out.print( "\n\nEnter Student ID and press return >> " );
		UserChoice = Terminal.KeyboardReadString();

		StudentObject =  ListObject.FindStudentByID( UserChoice );

		if ( StudentObject == null )
		{
			System.out.println( "\n\n*** Student ID " + UserChoice + " not found ***" );

		} // if

		return( StudentObject );

	} // PickStudent

	// This method allows the user to select a course

	public Course PickCourse( CourseList ListObject )
	{
		Termio Terminal = new Termio();
		String UserChoiceCourseID;
		String UserChoiceSection;
		Course CourseObject = null;

		System.out.print( "\n\nEnter Course ID and press return >> " );
		UserChoiceCourseID = Terminal.KeyboardReadString();

		System.out.print( "\n\nEnter Course Section and press return >> " );
		UserChoiceSection = Terminal.KeyboardReadString();

		CourseObject = ListObject.FindCourseByIDAndSection( UserChoiceCourseID,
										    UserChoiceSection   );

		if ( CourseObject == null )
		{
			System.out.print( "\n\n*** Course ID:" + UserChoiceCourseID );
			System.out.println( " Section:" + UserChoiceSection + " not found ***" );

		} // if

		return( CourseObject );

	} // PickCourse

	

	
	// This method allows the user to select a course

	public Course PickCourseWithoutSection( CourseList ListObject )
	{
		Termio Terminal = new Termio();
		String UserChoiceCourseID;
		Course CourseObject = null;

		System.out.print( "\n\nEnter Course ID and press return >> " );
		UserChoiceCourseID = Terminal.KeyboardReadString();

		

		CourseObject = new Course(UserChoiceCourseID);

		if ( !ListObject.FindCourse(CourseObject) )
		{
			System.out.print( "\n\n*** Course ID:" + UserChoiceCourseID );
			System.out.println( " not found ***" );
			return null;
		} // if
		

		return( CourseObject );

	} // PickCourse
} // Menus